package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service
public class ParticipantService {

    @Autowired
    private ParticipantMapper participantMapper;

    public int create(Participant participant) {
        return participantMapper.create(participant);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                participantMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return participantMapper.delete(id);
    }

    public int update(Participant participant) {
        return participantMapper.update(participant);
    }

    public int updateSelective(Participant participant) {
        return participantMapper.updateSelective(participant);
    }

    public PageInfo<Participant> query(Participant participant) {
        if(participant != null && participant.getPage() != null){
            PageHelper.startPage(participant.getPage(),participant.getLimit());
        }
        return new PageInfo<Participant>(participantMapper.query(participant));
    }

    public Participant detail(Integer id) {
        return participantMapper.detail(id);
    }

    public int count(Participant participant) {
        return participantMapper.count(participant);
    }
}
